﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PSE.Framework.UI.Controls.SmartClient
{
    public enum ErrorType
    {
        ServerError,
        ClientValidationError,
        ClientGeneralError
    }

    [Serializable]
    public class ErrorDetail : Base.Model.ErrorDetail
    {
        public ErrorDetail(int id)
            : base(id)
        {
        }

        public ErrorDetail(int id, string message)
            : base(id, message)
        {
        }

        public ErrorDetail(int id, string message, ErrorType type)
            : this(id, message)
        {
            _type = type;
        }

        private ErrorType _type;
        public ErrorType Type
        {
            get { return _type; }
            set { _type = value; }
        }

        public static ErrorDetail[] CreateFromException(Exception ex, ErrorType type)
        {
            Base.Model.ErrorDetail[] baseDetails = CreateFromException(ex);
            List<ErrorDetail> details = new List<ErrorDetail>();

            foreach (Base.Model.ErrorDetail baseDetail in baseDetails)
            {
                details.Add(new ErrorDetail(baseDetail.Id, baseDetail.Message, type));
            }

            return details.ToArray();
        }
    }
}
